﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string strGame = Page.RouteData.Values["gamename"].ToString();
        string playGame = clsDB.PlayGame(strGame);
        if (playGame.Length < 1)
            Response.Redirect("/default.aspx");

        cphMain.Controls.Add(new LiteralControl(playGame));

        System.Data.DataRow myDR = clsDB.GameInfo(strGame).Rows[0];
        string strTitle = myDR["title"].ToString();
        Page.Title = strTitle;
        string strDesc = myDR["description"].ToString();
        if (strDesc.Length < 1) strDesc = strTitle;
        strDesc = System.Web.HttpUtility.HtmlDecode(strDesc);
        string strURL = HttpContext.Current.Request.Url.AbsoluteUri;
        string strKey = myDR["keywords"].ToString();
        if (strKey.Length < 1) strKey = strTitle;
        string strImage = myDR["large_img"].ToString();
        if(strImage.Length < 1 ) strImage = myDR["thumbnail"].ToString();
        cphHead.Controls.Add(new LiteralControl("<meta name='description' content='"+ strDesc +"' />"));
        cphHead.Controls.Add(new LiteralControl("<meta name='keywords' content='"+ strKey +"' />"));
        cphHead.Controls.Add(new LiteralControl("<meta name='og:title' content='"+ strTitle +"' />"));
        cphHead.Controls.Add(new LiteralControl("<meta name='og:description' content='"+ strDesc +"' />"));
        cphHead.Controls.Add(new LiteralControl("<meta name='og:url' content='"+ strURL +"' />"));
        cphHead.Controls.Add(new LiteralControl("<meta name='og:image' content='"+ strImage +"' />"));
        cphHead.Controls.Add(new LiteralControl("<meta name='og:type' content='article' />"));
        cphHead.Controls.Add(new LiteralControl("<meta name='twitter:title' content='"+ strTitle +"' />"));
        cphHead.Controls.Add(new LiteralControl("<meta name='twitter:description' content='"+ strDesc +"' />"));
        cphHead.Controls.Add(new LiteralControl("<meta name='twitter:url' content='"+ strURL +"' />"));
        cphHead.Controls.Add(new LiteralControl("<meta name='twitter:image' content='"+ strImage +"' />"));
        cphHead.Controls.Add(new LiteralControl("<meta name='twitter:card' content='summary' />"));

        SqlDataSource1.SelectCommand = "select top 5 * from game where active=1 and id in (select game_id from catgame where category_id in (select category_id from catgame where game_id in (select ID from game where latin_title='" + strGame + "'))) order by featured desc, plays_total desc, added desc";
    }
}